/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import BO.Iter.GiaoVuBO;
import TableModel.Giaovu;
import java.awt.event.ActionEvent;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;

/**
 *
 * @author vt
 */
public class GiaoVuController {
     private GiaoVuBO gvBO;
    String strId;
    Giaovu bean;
    
    public GiaoVuBO getGvBO() {
        return gvBO;
    }

    public void setGvBO(GiaoVuBO gvBO) {
        this.gvBO = gvBO;
    }
    
    public void init(){
         
    }
    public Giaovu getBean() {
        return bean;
    }
    /**
     * phuong thuc nay dung de lay ve bean giao vu. nam trong form giao vu edit
     * khi co request xay ra thi phuong thuc nay lay ve duoc
     * 
      bean = gia tri moi 
     */
   public String getRequest(){
       FacesContext context = FacesContext.getCurrentInstance(); 
       Map map = context.getExternalContext().getRequestParameterMap();
       String id = (String) map.get("id_giaovu");
       System.out.println("id of GetRequest in Giao vu: " + id);
       bean = gvBO.findGiaoVu(id);
       return id;
   }
    public void setBean(Giaovu bean) {
        this.bean = bean;
    }

    public String getStrId() {
        return strId;
    }

    public void setStrId(String strId) {
        this.strId = strId;
    }
    public GiaoVuBO getMhBO() {
        return gvBO;
    }

    public void setMhBO(GiaoVuBO mhBO) {
        this.gvBO = mhBO;
    }
    /**
     * liet ke tat ca các giao vu co trong table
     * @return 
     */
    public List<Giaovu> getAll(){
        System.out.println("name of mhBO: " + gvBO.toString());
       return  gvBO.findAllGiaoVu();
    }
    
    
    public String actionEdit() { 
        return "gvuedit";
    }
    public String actionNew(){
        return "gvadd";
    }
    public void actionListenerEdit(ActionEvent  event){
            // getMonHocById();
    }
    public String movePageShow(Giaovu a){
        System.out.println(a.toString());
               gvBO.update(a);
           return "gvushow?faces-redirect=true";
    }
    public String addAndExit(Giaovu a){
        System.out.println(a.toString());
               gvBO.add(a);
           return "gvushow?faces-redirect=true";
    }
    public void delete (Giaovu a){
        try{
            gvBO.delete(a);
        }catch(Exception e){
            
        }
    }
    
}
